from selenium.webdriver.common.by import By
from utils.base import BaseObject, BaseHandle


class SearchObject:
    def __init__(self):
        self.bo = BaseObject()
        self.search_input = (By.ID, "android:id/search_src_text")
        self.search_result = (By.ID, "com.android.settings:id/title")

    def find_search_input(self):
        return self.bo.search_ele(self.search_input)

    def find_search_result(self):
        return self.bo.search_eles(self.search_result)


class SearchHandle:
    def __init__(self):
        self.bh = BaseHandle()
        self.so = SearchObject()

    def input_search_text(self, text):
        self.bh.input(self.so.find_search_input(), text)

    def get_search_text(self):
        res = self.so.find_search_result()
        return [i.text for i in res]


class SearchTask:
    sh = SearchHandle()
    @classmethod
    def search(cls, text):
        cls.sh.input_search_text(text)
        return cls.sh.get_search_text()
